package demo.ejs.result;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.JSONUtil;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.Result;
import com.opensymphony.xwork2.util.ValueStack;

public class JSONResult implements Result {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void execute(ActionInvocation invocation) throws Exception {

		HttpServletResponse response = ServletActionContext.getResponse();
		response.setContentType("application/json; charset=UTF-8");  
        final PrintWriter out = response.getWriter();
        try {  
        	 MyDTO dto1=new MyDTO("d1","Lucy",998.0,"JSON",100);
             MyDTO dto2=new MyDTO("d2","Jack",998.0,"JSON",100);
             MyDTO dto3=new MyDTO("d3","Lydia",998.0,"JSON",100);
             
            out.println("{\"Body\":[");
            //page 1
//            out.println("[");
//            out.println(dto1.toJSONString()+",");
//            out.println(dto2.toJSONString()+",");
//            out.println(dto3.toJSONString());
//            out.println("],");
            //page 2
            out.println("[");
            out.println(dto1.toJSONString()+",");
            out.println(dto2.toJSONString()+",");
            out.println(dto3.toJSONString());
            out.println("]");
            
            out.println("]}");
            
        } catch (Exception e) {  
             
        }  
        out.close();
	}

}
